<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="人员编号" prop="employeeId">
        <el-input
          v-model="queryParams.employeeId"
          placeholder="请输入人员编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位中类" prop="jobCategory">
        <el-input
          v-model="queryParams.jobCategory"
          placeholder="请输入岗位中类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职称等级分数" prop="titleLevelScore">
        <el-input
          v-model="queryParams.titleLevelScore"
          placeholder="请输入职称等级分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职业资格分数" prop="qualificationScore">
        <el-input
          v-model="queryParams.qualificationScore"
          placeholder="请输入职业资格分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="表彰奖励分数" prop="awardScore">
        <el-input
          v-model="queryParams.awardScore"
          placeholder="请输入表彰奖励分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训贡献分数" prop="trainingContributionScore">
        <el-input
          v-model="queryParams.trainingContributionScore"
          placeholder="请输入培训贡献分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训参与分数" prop="trainingParticipationScore">
        <el-input
          v-model="queryParams.trainingParticipationScore"
          placeholder="请输入培训参与分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作实践分数" prop="workPracticeScore">
        <el-input
          v-model="queryParams.workPracticeScore"
          placeholder="请输入工作实践分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位经历分数" prop="jobExperienceScore">
        <el-input
          v-model="queryParams.jobExperienceScore"
          placeholder="请输入岗位经历分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承担重点工作任务分数" prop="keyTaskScore">
        <el-input
          v-model="queryParams.keyTaskScore"
          placeholder="请输入承担重点工作任务分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="履职绩效分数" prop="performanceScore">
        <el-input
          v-model="queryParams.performanceScore"
          placeholder="请输入履职绩效分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作目标任务分数" prop="goalTaskScore">
        <el-input
          v-model="queryParams.goalTaskScore"
          placeholder="请输入工作目标任务分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="全年出班天数分数" prop="annualWorkingDaysScore">
        <el-input
          v-model="queryParams.annualWorkingDaysScore"
          placeholder="请输入全年出班天数分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="论文论著分数" prop="paperScore">
        <el-input
          v-model="queryParams.paperScore"
          placeholder="请输入论文论著分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创新成果分数" prop="innovationScore">
        <el-input
          v-model="queryParams.innovationScore"
          placeholder="请输入创新成果分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提升意愿分数" prop="willingnessToImproveScore">
        <el-input
          v-model="queryParams.willingnessToImproveScore"
          placeholder="请输入提升意愿分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="履职能力分数" prop="performanceAbilityScore">
        <el-input
          v-model="queryParams.performanceAbilityScore"
          placeholder="请输入履职能力分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="集中培训学时" prop="centralizedTrainingHours">
        <el-input
          v-model="queryParams.centralizedTrainingHours"
          placeholder="请输入集中培训学时"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="网络自学学时" prop="onlineSelfStudyHours">
        <el-input
          v-model="queryParams.onlineSelfStudyHours"
          placeholder="请输入网络自学学时"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评级星级" prop="ratingStar">
        <el-input
          v-model="queryParams.ratingStar"
          placeholder="请输入评级星级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年度" prop="awardYear">
        <el-date-picker clearable
                        v-model="queryParams.awardYear"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择年度">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="汉字星级名称" prop="ratingStarName">
        <el-input
          v-model="queryParams.ratingStarName"
          placeholder="请输入汉字星级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="等级名称" prop="levelName">
        <el-input
          v-model="queryParams.levelName"
          placeholder="请输入等级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:score:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:score:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:score:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:score:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scoreList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="人员编号" align="center" prop="employeeId" />
      <el-table-column label="岗位中类" align="center" prop="jobCategory" />
      <el-table-column label="职称等级分数" align="center" prop="titleLevelScore" />
      <el-table-column label="职业资格分数" align="center" prop="qualificationScore" />
      <el-table-column label="表彰奖励分数" align="center" prop="awardScore" />
      <el-table-column label="培训贡献分数" align="center" prop="trainingContributionScore" />
      <el-table-column label="培训参与分数" align="center" prop="trainingParticipationScore" />
      <el-table-column label="工作实践分数" align="center" prop="workPracticeScore" />
      <el-table-column label="岗位经历分数" align="center" prop="jobExperienceScore" />
      <el-table-column label="承担重点工作任务分数" align="center" prop="keyTaskScore" />
      <el-table-column label="履职绩效分数" align="center" prop="performanceScore" />
      <el-table-column label="工作目标任务分数" align="center" prop="goalTaskScore" />
      <el-table-column label="全年出班天数分数" align="center" prop="annualWorkingDaysScore" />
      <el-table-column label="论文论著分数" align="center" prop="paperScore" />
      <el-table-column label="创新成果分数" align="center" prop="innovationScore" />
      <el-table-column label="提升意愿分数" align="center" prop="willingnessToImproveScore" />
      <el-table-column label="履职能力分数" align="center" prop="performanceAbilityScore" />
      <el-table-column label="集中培训学时" align="center" prop="centralizedTrainingHours" />
      <el-table-column label="网络自学学时" align="center" prop="onlineSelfStudyHours" />
      <el-table-column label="评级星级" align="center" prop="ratingStar" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="年度" align="center" prop="awardYear" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.awardYear, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="汉字星级名称" align="center" prop="ratingStarName" />
      <el-table-column label="等级名称" align="center" prop="levelName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:score:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:score:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改员工积分对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="人员编号" prop="employeeId">
          <el-input v-model="form.employeeId" placeholder="请输入人员编号" />
        </el-form-item>
        <el-form-item label="岗位中类" prop="jobCategory">
          <el-input v-model="form.jobCategory" placeholder="请输入岗位中类" />
        </el-form-item>
        <el-form-item label="职称等级分数" prop="titleLevelScore">
          <el-input v-model="form.titleLevelScore" placeholder="请输入职称等级分数" />
        </el-form-item>
        <el-form-item label="职业资格分数" prop="qualificationScore">
          <el-input v-model="form.qualificationScore" placeholder="请输入职业资格分数" />
        </el-form-item>
        <el-form-item label="表彰奖励分数" prop="awardScore">
          <el-input v-model="form.awardScore" placeholder="请输入表彰奖励分数" />
        </el-form-item>
        <el-form-item label="培训贡献分数" prop="trainingContributionScore">
          <el-input v-model="form.trainingContributionScore" placeholder="请输入培训贡献分数" />
        </el-form-item>
        <el-form-item label="培训参与分数" prop="trainingParticipationScore">
          <el-input v-model="form.trainingParticipationScore" placeholder="请输入培训参与分数" />
        </el-form-item>
        <el-form-item label="工作实践分数" prop="workPracticeScore">
          <el-input v-model="form.workPracticeScore" placeholder="请输入工作实践分数" />
        </el-form-item>
        <el-form-item label="岗位经历分数" prop="jobExperienceScore">
          <el-input v-model="form.jobExperienceScore" placeholder="请输入岗位经历分数" />
        </el-form-item>
        <el-form-item label="承担重点工作任务分数" prop="keyTaskScore">
          <el-input v-model="form.keyTaskScore" placeholder="请输入承担重点工作任务分数" />
        </el-form-item>
        <el-form-item label="履职绩效分数" prop="performanceScore">
          <el-input v-model="form.performanceScore" placeholder="请输入履职绩效分数" />
        </el-form-item>
        <el-form-item label="工作目标任务分数" prop="goalTaskScore">
          <el-input v-model="form.goalTaskScore" placeholder="请输入工作目标任务分数" />
        </el-form-item>
        <el-form-item label="全年出班天数分数" prop="annualWorkingDaysScore">
          <el-input v-model="form.annualWorkingDaysScore" placeholder="请输入全年出班天数分数" />
        </el-form-item>
        <el-form-item label="论文论著分数" prop="paperScore">
          <el-input v-model="form.paperScore" placeholder="请输入论文论著分数" />
        </el-form-item>
        <el-form-item label="创新成果分数" prop="innovationScore">
          <el-input v-model="form.innovationScore" placeholder="请输入创新成果分数" />
        </el-form-item>
        <el-form-item label="提升意愿分数" prop="willingnessToImproveScore">
          <el-input v-model="form.willingnessToImproveScore" placeholder="请输入提升意愿分数" />
        </el-form-item>
        <el-form-item label="履职能力分数" prop="performanceAbilityScore">
          <el-input v-model="form.performanceAbilityScore" placeholder="请输入履职能力分数" />
        </el-form-item>
        <el-form-item label="集中培训学时" prop="centralizedTrainingHours">
          <el-input v-model="form.centralizedTrainingHours" placeholder="请输入集中培训学时" />
        </el-form-item>
        <el-form-item label="网络自学学时" prop="onlineSelfStudyHours">
          <el-input v-model="form.onlineSelfStudyHours" placeholder="请输入网络自学学时" />
        </el-form-item>
        <el-form-item label="评级星级" prop="ratingStar">
          <el-input v-model="form.ratingStar" placeholder="请输入评级星级" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="年度" prop="awardYear">
          <el-date-picker clearable
                          v-model="form.awardYear"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择年度">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="汉字星级名称" prop="ratingStarName">
          <el-input v-model="form.ratingStarName" placeholder="请输入汉字星级名称" />
        </el-form-item>
        <el-form-item label="等级名称" prop="levelName">
          <el-input v-model="form.levelName" placeholder="请输入等级名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScore, getScore, delScore, addScore, updateScore } from "@/api/business/score";

export default {
  name: "Score",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工积分表格数据
      scoreList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        employeeId: null,
        jobCategory: null,
        titleLevelScore: null,
        qualificationScore: null,
        awardScore: null,
        trainingContributionScore: null,
        trainingParticipationScore: null,
        workPracticeScore: null,
        jobExperienceScore: null,
        keyTaskScore: null,
        performanceScore: null,
        goalTaskScore: null,
        annualWorkingDaysScore: null,
        paperScore: null,
        innovationScore: null,
        willingnessToImproveScore: null,
        performanceAbilityScore: null,
        centralizedTrainingHours: null,
        onlineSelfStudyHours: null,
        ratingStar: null,
        remarks: null,
        awardYear: null,
        ratingStarName: null,
        levelName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询员工积分列表 */
    getList() {
      this.loading = true;
      listScore(this.queryParams).then(response => {
        this.scoreList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        employeeId: null,
        jobCategory: null,
        titleLevelScore: null,
        qualificationScore: null,
        awardScore: null,
        trainingContributionScore: null,
        trainingParticipationScore: null,
        workPracticeScore: null,
        jobExperienceScore: null,
        keyTaskScore: null,
        performanceScore: null,
        goalTaskScore: null,
        annualWorkingDaysScore: null,
        paperScore: null,
        innovationScore: null,
        willingnessToImproveScore: null,
        performanceAbilityScore: null,
        centralizedTrainingHours: null,
        onlineSelfStudyHours: null,
        ratingStar: null,
        remarks: null,
        awardYear: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        ratingStarName: null,
        levelName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加员工积分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getScore(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改员工积分";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateScore(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScore(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除员工积分编号为"' + ids + '"的数据项？').then(function() {
        return delScore(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/score/export', {
        ...this.queryParams
      }, `score_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
